package utils;

import FCRendering.FCRMaster;
import Function.FCMutilPlayCache;
import Function.FCMutilPlayPropulsionCache;
import Function.FCTankLibrary;
import Function.Utils.CacheFileUtil;
import VWorldGameStudio.*;
import VWorldGameStudio.events.*;
import VWorldGameStudio.touzi.BaiShuDIProject;
import VWorldGameStudio.touzi.BoBuSchoolProject;
import VWorldGameStudio.touzi.BoBuShaTanProject;
import VWorldGameStudio.touzi.FCTouZiProject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import utils.entity.BigSavePack;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.function.BiConsumer;

import static FCRendering.FCRConstants.DEBUG_MODE;
import static FCRendering.FCRMaster.fcv;


/**
 * 数据（文件）的读取操作在这里完成<br>
 * 查看写操作类，删除操作类请跳转以下链接：<br>
 *
 * @author jungle
 * @see utils.FCDataWrite
 * @see utils.FCDataDelete
 */
public class FCDataRead implements FCDataReadable {
    /**
     * 读取数据
     */
    private BufferedReader reader;
    Gson gson = new Gson();

    protected FCDataRead() {
    }

    /**
     * 读取存档
     */
    @Override
    public boolean readSaveData(FCPlayerInfo player1,
                                FCSave gamesave, FCDate gamedate, FCTankLibrary tankl, String url) {
        try {
            String bigData = CacheFileUtil.getInstance().readCacheInfo(url);
            String bigData2 = FCMixUtil.uncompress(bigData);
            BigSavePack bigSavePack = gson.fromJson(bigData2, BigSavePack.class);
            FCRMaster.gameSave = bigSavePack.gameSave;
            FCRMaster.gamedate = bigSavePack.gameDate;
            FCRMaster.player1 = bigSavePack.player1;
            //TEST
            if(DEBUG_MODE) {
                FCRMaster.player1.setBloodMax(999);
                FCRMaster.player1.setBlood(999);
                FCRMaster.player1.setMoney(999999);
                FCRMaster.gameSave.perV = 12;
            } else {
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*8", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*9", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*10", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*11", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*12", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*13", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*14", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*6*15", "hideplace");
                FCRMaster.gameSave.getOtherEventMaps().put("home1*8*4", "hideplace");
            }

            //必须滴
            FCRMaster.itemLib.setExtraItemCloneImpl(FCRMaster.gameSave);
            Iterator<Map.Entry<String, FCTank>> iterator = FCRMaster.gameSave.getTankSaveIos().entrySet().iterator();
            while (iterator.hasNext()) {
                iterator.next().getValue().reInitShuxing();
            }
            for (String fc : FCRMaster.gameSave.getSaveFCPropulsionStrings()) {
                String[] pSplits = fc.split(",");
                FCPropulsion searchOne = null;
                if (pSplits[3].equals("tank")) {
                    searchOne = tankl.getTankOfID(pSplits[1], pSplits[2]);
                    if (searchOne != null) {
                        ((FCTank) searchOne).reInitShuxing();
                    }
                }
                if (searchOne != null) {
                    searchOne.setPmapname(pSplits[0]);
                    searchOne.setPcoorX(Integer.parseInt(pSplits[4]));
                    searchOne.setPcoorY(Integer.parseInt(pSplits[5]));
                    searchOne.setPPianYiX(Integer.parseInt(pSplits[6]));
                    searchOne.setPPianYiY(Integer.parseInt(pSplits[7]));
                    searchOne.setBeingTow(Integer.parseInt(pSplits[8]));
                    searchOne.setPdir(Integer.parseInt(pSplits[9]));
                    searchOne.setPactionNum(Integer.parseInt(pSplits[10]));
                    searchOne.setVisable(Integer.parseInt(pSplits[11]));

                    if (!fcv.getLocalPropulsions().contains(searchOne)) {
                        fcv.getLocalPropulsions().add(searchOne);
                    }
                    if (searchOne.getBeingTow() > 0) {
                        FCRMaster.player1.addPropulsion(searchOne);
                    }

                    FCMutilPlayPropulsionCache.loacalShareIt(searchOne);
                    //System.out.println("read searchOne "+searchOne.getSaveString()+" s:"+fcv.getLocalPropulsions().size());
                }
            }
            //TEST
            // FCRMaster.gameSave.getBattleBossMaps().clear();
            //   FCRMaster.gameSave.setPlotisend(new HashMap<>());
            //   gameSave.getFcEventHasHanppen().clear();
            System.out.println("read:" + gson.toJson(FCRMaster.gameSave));
            ArrayList<FCPlayerInfo> teams = bigSavePack.teams;
            if (teams != null) {
                for (FCPlayerInfo npc : teams) {
                    FCMutilPlayCache.joinGame(npc);
                    FCRMaster.player1.joinInTeam(npc);
                }
            }
            FCRMaster.gameSave.getOutTeamLocalNpcs().forEach(new BiConsumer<String, FCPlayerInfo>() {
                @Override
                public void accept(String s, FCPlayerInfo playerInfo) {
                    FCMutilPlayCache.joinGame(playerInfo);
                }
            });
            ArrayList<FCTouZiProject> newTouzi = new ArrayList<>();
            for(FCTouZiProject e: FCRMaster.gameSave.getTouZiProjects()){
                if(e.projectEnName.equals("boBuShaTan")){
                    newTouzi.add(new BoBuShaTanProject(e));
                }else if(e.projectEnName.equals("boBuSchool")){
                    newTouzi.add(new BoBuSchoolProject(e));
                }else if(e.projectEnName.equals("baishuDi")){
                    newTouzi.add(new BaiShuDIProject(e));
                }
            }
            FCRMaster.gameSave.getTouZiProjects().clear();
            FCRMaster.gameSave.getTouZiProjects().addAll(newTouzi);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 读取剧情数据
     */
    @Override
    public FCPlot readPlotData(String url) {
        try {
            String id = "", touchoff = "";
            Vector<String> active = new Vector<>();
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(url), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("id=") > -1 && str.indexOf("id=") < 4)
                    id = str.substring(3);
                if (str.indexOf("touchoff=") > -1)
                    touchoff = str.substring(9);
//				if(str.indexOf("active=")>-1)active0=new String[Integer.valueOf(str.substring(7))];
                if (str.indexOf("active[") > -1)
                    active.add(str.substring(str.indexOf("]=") + 2));
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            FCPlot pl = new FCPlot();
            pl.registerPlot(id, touchoff, active);
            return pl;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 读取攻击动画
     */
    @Override
    public FCAnimation readAnimationData(String url) {
        try {
            FCAnimation e = new FCAnimation();
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(url), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("id=") > -1 && str.indexOf("id=") < 1)
                    e.setId(str.split("=")[1]);
                if (str.indexOf("type=") > -1)
                    e.setType(str.split("=")[1]);
                if (str.indexOf("forwho=") > -1)
                    e.setAnimationForWho(Integer.valueOf(str.split("=")[1]));
                if (str.indexOf("fire=") > -1) {
                    String s = str.split("=")[1];
                    String[] sp1 = s.split(",");
                    e.fireFrameTime = Integer.valueOf(sp1[0]);
                    e.setFireMusicId(Integer.valueOf(sp1[1]));
                    e.firePngSizeW = Integer.valueOf(sp1[2]);
                    e.firePngSizeH = Integer.valueOf(sp1[3]);
                    e.firePngCenterOffsetX = Integer.valueOf(sp1[4]);
                    e.firePngCenterOffsetY = Integer.valueOf(sp1[5]);
                    for (int i = 0; i < Integer.valueOf(sp1[6]); i++) {
                        e.getFirePngUrl().add(sp1[7 + i]);
                    }
                }
                if (str.indexOf("fly=") > -1) {
                    String s2 = str.split("=")[1];
                    String[] sp2 = s2.split(",");
                    e.setFlyMusicId(Integer.valueOf(sp2[1]));
                    e.flyingPngSizeW = Integer.valueOf(sp2[2]);
                    e.flyingPngSizeH = Integer.valueOf(sp2[3]);
                    e.flyingPngCenterOffsetX = Integer.valueOf(sp2[4]);
                    e.flyingPngCenterOffsetY = Integer.valueOf(sp2[5]);
                    for (int i = 0; i < Integer.valueOf(sp2[6]); i++) {
                        e.getFlyingPngUrl().add(sp2[7 + i]);
                    }
                }
                if (str.indexOf("fly2=") > -1) {
                    String s22 = str.split("=")[1];
                    String[] sp22 = s22.split(",");
                    e.setFlyMusicId2(Integer.valueOf(sp22[1]));
                    e.flyingPngSizeW2 = Integer.valueOf(sp22[2]);
                    e.flyingPngSizeH2 = Integer.valueOf(sp22[3]);
                    e.flyingPngCenterOffsetX2 = Integer.valueOf(sp22[4]);
                    e.flyingPngCenterOffsetY2 = Integer.valueOf(sp22[5]);
                    for (int i = 0; i < Integer.valueOf(sp22[6]); i++) {
                        e.getFlyingPngUrl2().add(sp22[7 + i]);
                    }
                }
                if (str.indexOf("boom=") > -1) {
                    String s3 = str.split("=")[1];
                    String[] sp3 = s3.split(",");
                    e.boomFrameTime = Integer.valueOf(sp3[0]);
                    e.setBoomMusicId(Integer.valueOf(sp3[1]));
                    e.boomPngSizeW = Integer.valueOf(sp3[2]);
                    e.boomPngSizeH = Integer.valueOf(sp3[3]);
                    e.boomPngCenterOffsetX = Integer.valueOf(sp3[4]);
                    e.boomPngCenterOffsetY = Integer.valueOf(sp3[5]);
                    for (int i = 0; i < Integer.valueOf(sp3[6]); i++) {
                        e.getBoomPngUrl().add(sp3[7 + i]);
                    }
                }
                if (str.indexOf("boomScale=") > -1) {
                    e.boomPngScales = Double.parseDouble(str.split("=")[1]);
                }

                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            e.initAllImages();
            return e;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 读取动作
     */
    @Override
    public FCAction readActionData(String url) {
        try {
            String name = null, type = null, as = null;
            int face = 0;
            ArrayList<String> route = new ArrayList<String>();
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(url), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("name=") > -1)
                    name = str.split("=")[1];
                if (str.indexOf("type=") > -1)
                    type = str.split("=")[1];
                if (str.contains("fixedroute=")) {
                    String data = str.split("=")[1];
                    if (data != null && data.length() > 2) {
                        route = gson.fromJson(str.split("=")[1], new TypeToken<ArrayList<String>>() {
                        }.getType());
                    }
                }
                if (str.indexOf("face=") > -1)
                    face = Integer.valueOf(str.substring(5));
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            if (as != null) {
                as = as.substring(1, as.length() - 1);
                String zx[] = as.split(",");
                for (int i = 0; i < zx.length; i++)
                    route.add(zx[i]);
            }
            FCAction e = new FCAction(name, type, face, route);
            return e;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 读取事件
     */
    @Override
    public FCEvent readEventData(String url) {
        try {
            String str = CacheFileUtil.getInstance().readCacheInfo(url);

            FCEvent ret = gson.fromJson(str, FCEvent.class);
            if ("jump".equals(ret.getType())) {
                ret = gson.fromJson(str, JumpEvent.class);
            } else if ("shop".equals(ret.getType())) {
                ret = gson.fromJson(str, ShopEvent.class);
            } else if ("case".equals(ret.getType())) {
                ret = gson.fromJson(str, CaseEvent.class);
            } else if ("say".equals(ret.getType())) {
                ret = gson.fromJson(str, SayEvent.class);
            } else if ("phonograph".equals(ret.getType())) {
                ret = gson.fromJson(str, PhonographEvent.class);
            } else if ("on-off".equals(ret.getType())) {
                ret = gson.fromJson(str, OnOffEvent.class);
            } else if ("battle".equals(ret.getType())) {
                ret = gson.fromJson(str, BattleEvent.class);
            } else if ("itemCtrl".equals(ret.getType())) {
                ret = gson.fromJson(str, ItemCtrlEvent.class);
            } else if ("stepOn".equals(ret.getType())) {
                ret = gson.fromJson(str, StepOnEvent.class);
            } else if ("mapHiddenItem".equals(ret.getType())) {
                ret = gson.fromJson(str, MapHiddenEvent.class);
            } else if ("door".equals(ret.getType())) {
                ret = gson.fromJson(str, DoorEvent.class);
            }
            return ret;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 读取地图
     */
    @Override
    public FCMap readMapData(int ID, String url) {
        try {
            String name = null, info = null, unplace1[] = null, place1[] = null, eventname1[] = null, entity1[] = null,
                    entity2[] = null, backgroundurl = null, mapnpc = null, maptank = null;
            int width = 0, hight = 0;
            HashMap<String, String> mapAni = new HashMap<>();
            ArrayList<FCMapAndMsEntity> mapAndMsEntities = new ArrayList<>(0);
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(url), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("name=") > -1 && str.indexOf("name=") < 2)
                    name = str.split("=")[1];
                if (str.indexOf("info=") > -1)
                    info = str.split("=")[1];
                if (str.indexOf("size=") > -1) {
                    String[] qwe = str.split("=")[1].split("/");
                    width = Integer.valueOf(qwe[0]);
                    hight = Integer.valueOf(qwe[1]);
                }
                if (str.indexOf("unplace=") > -1)
                    unplace1 = new String[Integer.valueOf(str.split("=")[1])];
                if (str.indexOf("place=") > -1)
                    place1 = new String[Integer.valueOf(str.split("=")[1])];
                if (str.indexOf("eventname=") > -1)
                    eventname1 = new String[Integer.valueOf(str.split("=")[1])];
                if (str.indexOf("entity1=") > -1)
                    entity1 = new String[Integer.valueOf(str.split("=")[1])];
                if (str.indexOf("entity2=") > -1)
                    entity2 = new String[Integer.valueOf(str.split("=")[1])];
                if (str.indexOf("background=") > -1)
                    backgroundurl = str.split("=")[1];
                if (str.indexOf("unplace[") > -1) {
                    String q[] = str.substring(8).split("]=");
                    unplace1[Integer.valueOf(q[0])] = q[1];
                }
                if (str.indexOf("place[") > -1 && str.indexOf("place[") < 2) {
                    String q[] = str.substring(6).split("]=");
                    place1[Integer.valueOf(q[0])] = q[1];
                }
                if (str.indexOf("eventname[") > -1) {
                    String q[] = str.substring(10).split("]=");
                    eventname1[Integer.valueOf(q[0])] = q[1];
                }
                if (str.indexOf("entity1[") > -1) {
                    String q[] = str.substring(8).split("]=");
                    entity1[Integer.valueOf(q[0])] = q[1];
                }
                if (str.indexOf("entity2[") > -1) {
                    String q[] = str.substring(8).split("]=");
                    entity2[Integer.valueOf(q[0])] = q[1];
                }
                if (str.indexOf("mapnpc=") > -1) {
                    mapnpc = str.substring(7);
                }
                if (str.indexOf("maptank=") > -1) {
                    maptank = str.substring(8);
                }
//                if (str.indexOf("monsterid=") > -1)
//                    monstera = new String[Integer.valueOf(str.split("=")[1])];
//                if (str.indexOf("monsterid[") > -1) {
//                    String q[] = str.substring(10).split("]=");
//                    monstera[Integer.valueOf(q[0])] = q[1];
//                }
                if (str.contains("monsterArea=")) {
                    String d = str.split("=")[1];
                    mapAndMsEntities = gson.fromJson(d, new TypeToken<ArrayList<FCMapAndMsEntity>>() {
                    }.getType());
                }

                if (str.contains("mapAni=")) {
                    String d = str.split("=")[1];
                    mapAni = gson.fromJson(d, new TypeToken<HashMap<String, String>>() {
                    }.getType());
                }

                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            String[][] unplace = new String[unplace1.length][unplace1[0].split("/").length];
            String[][] place = new String[place1.length][place1[0].split("/").length];
            String[][] eventname = new String[eventname1.length][eventname1[0].split("/").length];
//			String [][]monsterid=new String[monstera.length][monstera[0].split("/").length];
//            String[][] monsterid = new String[eventname1.length][eventname1[0].split("/").length];
            int[][] entity11 = new int[entity1.length][entity1[0].split("/").length];
            int[][] entity22 = new int[entity2.length][entity2[0].split("/").length];
            for (int i = 0; i < unplace.length; i++) {
                String[] asd = unplace1[i].split("/");
                String[] zxc = place1[i].split("/");
                String[] wer = eventname1[i].split("/");
                String[] sdf = entity1[i].split("/");
                String[] xcv = entity2[i].split("/");

//				if(name.equals("DongXue2-1"))System.out.println(monstera[i]);
                for (int j = 0; j < unplace[0].length; j++) {
                    unplace[i][j] = asd[j];
                    place[i][j] = zxc[j];
                    eventname[i][j] = wer[j];
                    entity11[i][j] = Integer.valueOf(sdf[j]);
                    entity22[i][j] = Integer.valueOf(xcv[j]);
//					if(name.equals("DongXue2-1"))monsterid[i][j]="null";
//					else monsterid[i][j]=ert[j];
                }
            }
            HashMap<String, String> npc = new HashMap<>();
            HashMap<String, String> tank = new HashMap<>();
            if (mapnpc != null && mapnpc.length() > 0) {
                String nji[] = mapnpc.split("/");
                for (int i = 0; i < nji.length; i++) {
                    String[] bhu = nji[i].split(",");
                    npc.put(bhu[0], bhu[1]);
                }
            }
            if (maptank != null && maptank.length() > 0) {
                String nji[] = maptank.split("/");
                for (int i = 0; i < nji.length; i++) {
                    String[] bhu = nji[i].split(",");
                    tank.put(bhu[0], bhu[1]);
                }
            }

            FCMap m = new FCMap();
            m.registerMap(name, info, width, hight, unplace, place, entity11, entity22, eventname, backgroundurl, npc,
                    null, tank, mapAni, mapAndMsEntities);
            return m;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 读取怪物
     */
    @Override
    public FCMonster readMonsterData(int ID, String url) {
        try {
            String str = CacheFileUtil.getInstance().readCacheInfo(url);
            FCMonster ret = gson.fromJson(str, FCMonster.class);
            ret.initMonster();
            return ret;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 读取物品
     */
    @Override
    public FCItem readItemData(int ID, String url) {
        try {
            String str = CacheFileUtil.getInstance().readCacheInfo(url);
            FCItem ret = gson.fromJson(str, FCItem.class);
            ret.initItem();
            return ret;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 读取坦克
     */
    @Override
    public FCTank readTankData(String url) {
        try {
            String name = "tanks", masterPngUrl = null, actionPngUrl = null, whitelineurl = null, gunID = null,
                    gun2ID = null, engineID = null, CdeviceID = null, chassisID = null, radarID = null,
                    seID = null;
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(url), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("name=") > -1)
                    name = str.split("=")[1];
                if (str.indexOf("gunid=") > -1)
                    gunID = str.split("=")[1];
                if (str.indexOf("gun2id=") > -1)
                    gun2ID = str.split("=")[1];
                if (str.indexOf("engineid=") > -1)
                    engineID = str.split("=")[1];
                if (str.indexOf("cdeviceid=") > -1)
                    CdeviceID = str.split("=")[1];
                if (str.indexOf("chassisid=") > -1)
                    chassisID = str.split("=")[1];
                if (str.indexOf("radarid=") > -1)
                    radarID = str.split("=")[1];
                if (str.indexOf("masterpngurl=") > -1)
                    masterPngUrl = str.split("=")[1];
                if (str.indexOf("dirpngurl=") > -1)
                    actionPngUrl = str.split("=")[1];
                if (str.indexOf("whitelinepngurl=") > -1)
                    whitelineurl = str.split("=")[1];
                if (str.indexOf("SEid=") > -1)
                    seID = str.split("=")[1];
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());

            }
            reader.close();
            FCTank t = new FCTank();
            t.registerTank(name, gunID, gun2ID, seID, engineID, CdeviceID, chassisID, radarID, masterPngUrl, actionPngUrl,
                    whitelineurl);
            return t;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 读取人物
     */
    @Override
    public FCCharacter readCharacterData(int ID, String url) {
        try {
            String name = null, type = null, pngurl = null, actionid = null;
            String eventid = "null";
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(new File(url)), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("name=") > -1)
                    name = str.substring(5);
                if (str.indexOf("type=") > -1)
                    type = str.split("=")[1];
                if (str.indexOf("pngurl=") > -1)
                    pngurl = str.split("=")[1];
                if (str.indexOf("actionid=") > -1)
                    actionid = str.split("=")[1];
                if (str.indexOf("eventid=") > -1)
                    eventid = str.split("=")[1];
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            FCCharacter c = new FCCharacter();
            c.registerCharater(ID, name, type, actionid, (eventid.equals("-1")) ? "null" : eventid, pngurl);
            return c;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 读取方块
     */
    @Override
    public FCBlock readBlockData(String url) {
        try {
            String name = null, type = null, pngurl[] = null, model[] = null, coor[] = null;
            String eventid = null;
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(new File(url)), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.indexOf("name=") > -1)
                    name = str.split("=")[1];
                if (str.indexOf("type=") > -1)
                    type = str.split("=")[1];
                if (str.indexOf("eventid=") > -1)
                    eventid = str.split("=")[1];
                if (str.indexOf("pngurl=") > -1)
                    pngurl = str.split("=")[1].split("//");
                if (str.indexOf("model=") > -1)
                    model = str.split("=")[1].split("/");
                if (str.indexOf("coor=") > -1)
                    coor = str.split("=")[1].split("/");
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            int model1[][] = new int[model.length][model[0].split("v").length];
            for (int i = 0; i < model1.length; i++) {
                String qw[] = model[i].split("v");
                for (int j = 0; j < qw.length; j++) {
                    if (!qw[j].equals("zero"))
                        model1[i][j] = Integer.valueOf(qw[j]);
                    else
                        model1[i][j] = 0;
                }
            }
            int coor1[][] = new int[coor.length][coor[0].split("v").length];
            for (int i = 0; i < coor1.length; i++) {
                String qw[] = coor[i].split("v");
                for (int j = 0; j < qw.length; j++)
                    coor1[i][j] = Integer.valueOf(qw[j]);
            }
            FCBlock f = new FCBlock();
            f.registerBlock(name, type, pngurl, model1, coor1, eventid);
            return f;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public FCMapAnimation readMapAnimationData(String url) {
        try {
            String name = null;
            int w = 0, h = 0, level = 0, visiable = 0, playTime = -1;
            ArrayList<String> urls = new ArrayList<>(0);
            reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(new File(url)), "UTF-8"));
            String str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            while (str != null) {
                if (str.contains("name="))
                    name = str.split("=")[1];
                else if (str.contains("level="))
                    level = Integer.parseInt(str.split("=")[1]);
                else if (str.contains("imgW="))
                    w = Integer.parseInt(str.split("=")[1]);
                else if (str.contains("imgH="))
                    h = Integer.parseInt(str.split("=")[1]);
                else if (str.contains("visiable="))
                    visiable = Integer.parseInt(str.split("=")[1]);
                else if (str.contains("imgUrl=")) {
                    String d = str.split("=")[1];
                    urls = gson.fromJson(d, new TypeToken<ArrayList<String>>() {
                    }.getType());
                } else if (str.contains("playTimes=")) {
                    playTime = Integer.parseInt(str.split("=")[1]);
                }
                str = FCDataSingles.getDataDE().dataDecrypt(reader.readLine());
            }
            reader.close();
            FCMapAnimation fcMapAnimation = new FCMapAnimation();
            fcMapAnimation.registerMapAni(name, level, w, h, urls, visiable, playTime);
            return fcMapAnimation;
        } catch (Exception e) {
            return null;
        }
    }
}
